package com.small.nacos.core.cluster;


import com.small.nacos.common.notify.Event;

import java.util.Collection;

/**
 * @Author zhoujin
 * @Date 2022/11/7 13:54
 */
public class MembersChangeEvent extends Event {

    private static final long serialVersionUID = 7308126651076668976L;

    private Collection<Member> members;

    public static MemberChangeEventBuilder builder() {
        return new MemberChangeEventBuilder();
    }

    public Collection<Member> getMembers() {
        return members;
    }

    public void setMembers(Collection<Member> members) {
        this.members = members;
    }

    @Override
    public String toString() {
        return "MembersChangeEvent{" + "members=" + members + ", no=" + sequence() + '}';
    }

    public static final class MemberChangeEventBuilder {

        private Collection<Member> allMembers;

        private MemberChangeEventBuilder() {
        }

        public MemberChangeEventBuilder members(Collection<Member> allMembers) {
            this.allMembers = allMembers;
            return this;
        }

        /**
         * build MemberChangeEvent.
         *
         * @return {@link MembersChangeEvent}
         */
        public MembersChangeEvent build() {
            MembersChangeEvent membersChangeEvent = new MembersChangeEvent();
            membersChangeEvent.setMembers(allMembers);
            return membersChangeEvent;
        }
    }
}
